<?php if (!defined("BASEPATH")) exit("No direct script access allowed");

class Bet365 extends MY_Controller {

	private $insertedOdds = 0;

	function __construct() {
		parent::__construct();
	}
	
	function index() {

		$getHtmlByBookie = $this->html_model->getHtmlByBookie(strtolower(get_class()));
		if(count($getHtmlByBookie)) {
			foreach($getHtmlByBookie as $currhtml) {
				$this->insertedOdds = 0;
				$html = str_get_html($currhtml["html_text"]);
				$ScreenTitle = $html->find("div[id=ScreenTitle]",0)->innertext; 
				switch(true) {

					case (stristr($ScreenTitle, "Full Time Result") !== FALSE): {
						$table = $html->find("table[class=FTR]", 0);
						foreach($table->find("th[class=DarkMidGrey]") as $th) {
							$insUpd = array();
							$insUpd["odds_type"] = "3W";
							$insUpd["odds_html_id"] = $currhtml["html_id"];
							if($th->parent()->prev_sibling()->find("td[class=SubHeader]", 0)) {
								$odds_league = $insUpd["odds_league"] = Common::prepare_str($th->parent()->prev_sibling()->find("td[class=SubHeader]", 0)->innertext);
							} else {
								$insUpd["odds_league"] = ((isset($odds_league))?($odds_league):(NULL));
							}
							echo $th->innertext."<br/>";
						}
					} break;

					case (stristr($ScreenTitle, "Goals Over") !== FALSE): {
					
					} break;

					case (stristr($ScreenTitle, "Double Chance") !== FALSE): {
					
					} break;

				}

				$insUpd = array();

				exit;
                // html update
                $this->html_model->update($currhtml["html_id"], array(
					"html_parsed_time" => Common::now(),
					"html_inserted_odds" => $this->insertedOdds,
                ));
				exit;
                
			}
		}

	}

}